package edu.gmu.tec.surveilance.android;

import java.util.List;

import com.Message.msg.Message2;
import com.Message.msg.MessageType;

import android.app.Activity;
import edu.gmu.tec.comm.AbstractDeployerListener;
import edu.gmu.tec.comm.ClientSocket;
import edu.gmu.tec.comm.OutputEventHandler;
import edu.gmu.tec.types.Dossier;
import edu.gmu.tec.types.Payload;
import edu.gmu.tec.types.comms.InputEvent;

public class SurveilPlayer extends AbstractDeployerListener{

	public SurveilPlayer(Dossier dossier, Activity surveilActivity) {
		super(dossier);
		
	}

	public void ok(){
		if((briefing == null) || (briefing.equals(""))) {
            // do nothing
            System.out.println("Ok \n");
            System.out.println("No Activity Sheet => No action \n");
        }
        else {
            System.out.println("Ok \n");
            System.out.println(briefing);

            List<OutputEventHandler> targets = activitySheet.outputEventTargets("ok");
            ClientSocket clientSocket = new ClientSocket();

            for(OutputEventHandler target:targets) {
                String messageContent = "";
                try {
                    Message2 messageDoc = null;
                            messageDoc = Message2.createDocument();
                    MessageType message = messageDoc.Message3.append();
                    message.name.setValue(target.getName());

                    for (Payload p: activitySheet.getPayLoads("ok")) {
                            com.Message.as.Payload mp = message.payload.append();
                            mp.name.append().setValue(p.getName());
                            mp.type.append().setValue(p.getType());
                            mp.value2.append().setValue(p.getValue());
                    }

                    messageContent = messageDoc.saveToString(true);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }

                    System.out.println("Sending a Message to target player: \n" + messageContent);
                    System.out.println("Port: \n" + target.getIp() + "  " + target.getPort());
                    clientSocket.send(messageContent, target.getIp(), target.getPort());
            }
        }
	}
	@Override
	public void inputEventReceived(InputEvent event) {
		
		
	}

}
